# encoding:utf-8
import requests
from bs4 import BeautifulSoup

# 在此输入上网账号
username = 'your_username'
# 在此输入上网密码
password = 'your_password'

header = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0',
}

# 登录网络的地址
login_url = 'http://login.imau.edu.cn:802/include/auth_action.php'
# 查看网络流量使用情况的代码
data_use_url = 'http://login.imau.edu.cn:803/srun_portal_pc_succeed.php'

def data_use_status(url):
    resp = requests.get(url)
    bs = BeautifulSoup(resp.text,"html.parser")
    print("登陆ip地址:",bs.select('#sum_bytes')[0].get_text())
    print("已经使用流量:",bs.select('#sum_bytes')[1].get_text())

# 登录网络的参数
def loginNet(url,username,password):
    post_data ={
        'action':'login',
        'username':username,
        'password':password,
        'ac_id':1,
        'user_ip':'',
        'nas_ip':'',
        'user_mac':'',
        'save_me':0,
        'ajax':1
    }
    resp = requests.post(url, data=post_data, headers=header)
    if resp.text.split(',')[0] == 'login_ok':
        print("登录成功!")
        data_use_status(data_use_url)

    else:
        print("登录失败,请检查账号密码重试!")

if __name__ == '__main__':
    loginNet(login_url,username,password)




